#include "pthread.h"
#include "app_common.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>


void *sum0(void *arg){
    int b = *(int*)arg;
    sleep(1);
    int *result = (int *)malloc(sizeof(int)); 
    *result= b * b;
    
    return (void *)result;
}

int main(int argc, char const *argv[])
{
    int a[5] = {1,2,3,4,5};
    int b[5] = {0};
    int he = 0;
    void *result;
    pthread_t sum[5];
    long start_ms = app_common_getsystime();
    for (size_t i = 0; i < 5; i++)
    {
        pthread_create(&sum[i],NULL,sum0,(void *)&a[i]);
    }
    for (int i = 0; i < 5; i++)
    {
        pthread_join(sum[i],&result);
        b[i] = *(int *)(result);
        // he += *(int *)(result);
    }
    
    long end_ms = app_common_getsystime();
    printf("时间：%ld\n",end_ms - start_ms);
    for (int i = 0; i < 5; i++)
    {
        he += b[i]; 
    }
    
    printf("he:%d\n",he);
    
    return 0;
}
